package com.ostrich.module_more.themes.adapter

import android.os.Bundle
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentStatePagerAdapter
import com.ostrich.module_more.themes.ThemesDataFragment
import com.ostrich.module_more.themes.entity.Tab
import com.ostrich.module_more.themes.entity.ThemesTabEntity

/**
 * @Author : yaotianxue
 * @Time : On 2023/11/1 11:35
 * @Description : ThemesFragmentAdapter
 */
class ThemesFragmentAdapter(private val titles:MutableList<Tab>, val fm:FragmentManager):FragmentStatePagerAdapter(fm) {
    private val fragments:MutableList<Fragment> = mutableListOf()
    init {
        //title有几个，fragments就有几个
        repeat(titles.size) {
            val fragment = ThemesDataFragment()
            //传值
            val bundle = Bundle()
            bundle.putSerializable("tab",titles[it])
            fragment.arguments = bundle
            fragments += fragment
        }
    }


    override fun getCount(): Int {
        return titles.size
    }

    override fun getItem(position: Int): Fragment {
        return fragments[position]
    }

    override fun getPageTitle(position: Int): CharSequence? {
        return titles[position].name
    }
}